package com.example.speeddating.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;


@Component
public class urlSaveImage {
    private String path;

    @Value("${soulmate.path}")
    public void setPath(String path) {
        this.path = path;
    }

    public String getPath() {
        return path;
    }

    public void saveImage(String imageUrl, String destinationFile) throws IOException {
        URL url = new URL(imageUrl);
        Path destinationPath = Path.of(getPath()+destinationFile);
        Files.copy(url.openStream(), destinationPath, StandardCopyOption.REPLACE_EXISTING);
    }
}
